package com.film.controller.movie;

import com.alibaba.fastjson.JSONObject;
import com.film.jwt.JwtUtil;
import com.film.service.impl.movie.FetchMovieCategoriesServiceImpl;
import com.film.service.impl.movie.FetchMoviesServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.sql.SQLException;

@RestController
public class FetchMovieCategoriesController {
    @Autowired
    private FetchMovieCategoriesServiceImpl fetchMovieCategoriesService;
    @GetMapping("/movie/fetch/categories/{token}")
    public JSONObject fetchCategories(@PathVariable String token) throws SQLException {
        if (!JwtUtil.JwtVerify(token)) {
            JSONObject resp = new JSONObject();
            resp.put("error_message", "jwt验证错误");
            return resp;
        } else {
            return fetchMovieCategoriesService.fetchMovies();
        }
    }

}
